﻿using Alos.Entity;
using Alos.IRepository;
using PetaPoco;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Alos.Repository
{
    public class BasicClassInfoRepository : BaseRepository<BasicClassInfo>, IBasicClassInfoRepository
    {
        /// <summary>
        /// 根据用户编号获取当前所教班级
        /// </summary>
        /// <param name="id"></param>
        /// <param name="roleid"></param>
        /// <returns></returns>
        public IEnumerable<dynamic> GetBasicClassInfoByUid(int id)
        {
            var sql = Sql.Builder.Append(" SELECT B.ID,b.ClassName,(SELECT COUNT(C.ID) FROM SysUserInfo C WHERE C.ClassID=B.ID AND C.RoleId=3) StudentCount FROM BasicClassInfo B WHERE B.ID IN( SELECT A.ClassID FROM [dbo].[BasicClassTERelation] A Where  A.TeacherID=@0) ORDER BY B.ClassName ASC  ", id);

            return DBContext.Query<dynamic>(sql);

        }



        public IEnumerable<dynamic> GetClassById(string Id)
        {
            var sql = Sql.Builder.Append(@" SELECT A.ID,A.ClassName,C.GradeName,C.GradeCode,(SELECT COUNT(D.ID) FROM SysUserInfo D WHERE D.ClassID=A.ID) StudentCount FROM BasicClassInfo A
        INNER JOIN GradeInfo B ON A.GradeInfoId=B.Id
        INNER JOIN DicGrade C ON C.Id=B.GradeId WHERE A.ID IN(@0)", Id);

            return DBContext.Query<dynamic>(sql);
        }
    }
}
